package gientech.spring.micro.mq;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import gientech.spring.micro.dto.UserChangeEvent;
import gientech.spring.micro.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(topic = "topic_ensure_transfer", consumerGroup = "consumer_ensure_transfer")
@Slf4j
public class EnsureMessageConsumer implements RocketMQListener<String> {

    @Autowired
    private UserService userService;

    @Override
    public void onMessage(String  projectStr) {
        System.out.println("开始消费消息：" + projectStr);
        final JSONObject jsonObject = JSON.parseObject(projectStr);
        UserChangeEvent userChangeEvent = JSONObject.parseObject(jsonObject.getString("userChange"),UserChangeEvent.class);

        userService.doupdateUser(userChangeEvent);
    }
}
